package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: chenLiGuo
 * @create: 2020-11-11 14:57
 **/
@RestController
@RequestMapping("/sss")
public class TestController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/login")
    public ResultModel<Object> login(HttpServletRequest request, HttpSession session, String username, String password) throws Exception {
        if ("admin".equals(username) && "admin".equals(password)) {
            session.setAttribute("login", "admin");
            return new ResultModel<>().success("success");
        }else {
            return new ResultModel<>().error("error");
        }
    }

    @GetMapping("/queryList")
    public ResultModel<Object> queryList() {
        Map<String, Object> map = new HashMap<>();
        map.put("data",resumeService.queryList());
        return new ResultModel<>().success(map);
    }

    @GetMapping("/del")
    public ResultModel<Object> del(@RequestParam("id") Long id) {
        resumeService.delete(id);
        return new ResultModel<>().success("success");
    }

    @PostMapping("/saveOrUpdate")
    public ResultModel<Object> saveOrUpdate(@RequestBody Resume resume) {
        resumeService.add(resume);
        return new ResultModel<>().success("success");
    }

}
